const arr = [];
for (let i = 0; i < 1000; i++) {
  arr.push(i);
}
function binary_search(value, arr) {
  let left = 0,
    right = arr.length - 1,
    result = null;
  while (left <= right) {
    const mid = Math.floor((left + right) / 2);
    const midValue = arr[mid];
    if (value > midValue) {
      left = mid + 1;
    }
    if (value < midValue) {
      right = mid - 1;
    }
    if (value === midValue) {
      result = mid;
      return result;
    }
  }
  return result;
}

console.log(binary_search(44, arr));
